home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / The Director Toolkit v1.0.adf / Programs / Text / docread < prev    next >
Text File  |  1987-02-25  |  6KB  |  300 lines

  1.  
  2. rem   text reader
  3.  
  4.     getok=1000:clears=1100:docmd=1200:getevent=1300
  5.  
  6.     font=1:clr=3
  7.     charw=8
  8.     charh=10
  9.     cent=0
  10.     styl=0
  11.     spac=0
  12.     esc=124        :rem  the | signal character
  13.     xmax=610
  14.     ymax=180
  15.     xmin=20
  16.     ymin=28
  17.     eof=0
  18.  
  19.     load 1,"Toolkit:pictures/framer"    :rem  you may have to adjust this
  20.  
  21.     array 500,4
  22.     temp=100
  23.     pstart=temp+50
  24.     page=pstart
  25.     @(page)=0
  26.     abort 0
  27.     loadfont 1,8,"topaz.font"
  28.     loadfont 2,9,"topaz.font"
  29.     setfont font
  30.     pen 1,clr
  31.     margins xmin,xmax
  32.     mode=0
  33.     open mode,"docs"
  34.     if mode=0
  35.         center 1
  36.         move 0,100
  37.         pen 1,6
  38.         setfont 2
  39.         text "Can't open docs file"
  40.         gosub getok
  41.         end
  42.     endif
  43.  
  44. rem   top of page
  45. 8   
  46.     location v
  47.     @(page)=v    :rem  remember top of page
  48.     page=page+1
  49.     gosub clears
  50.  
  51. rem  next line
  52. 10    read v,$(0),90
  53.     if v=-1:goto 22:endif
  54.     in=0
  55.     if @(in)=0        :rem  newline
  56.         xloc=xmin
  57.         yloc=yloc+charh
  58.         if yloc > ymax
  59.             gosub getevent
  60.         endif
  61.         goto 10
  62.     endif
  63.  
  64. rem  proc any commands
  65. 11
  66.     if @(in)=32:in=in+1:goto 11:endif :rem  ignore leading spaces
  67.     if @(in)=0:goto 10:endif    :rem  eol
  68.     if @(in)=esc
  69.         gosub docmd
  70.         goto 11
  71.     endif
  72.  
  73.     word=in        :rem  beginning of section
  74.  
  75. rem  find end of section
  76. 12    c=@(in)
  77.     if c#esc & c#0
  78.         in=in+1
  79.         goto 12
  80.     endif
  81.     @(in)=0
  82.  
  83. rem  proc section
  84. 13
  85.     if @(in-1)=32    :rem  ignore trailing spaces
  86.         @(in)=c
  87.         in=in-1
  88.         c=@(in)
  89.         @(in)=0
  90.         goto 13
  91.     endif
  92.  
  93.     sectw=(charw+spac)*(in-word) 
  94.  
  95. rem  output a section
  96.     if (xloc+sectw)<xmax
  97.         sp=1
  98.         t=@(in-1)
  99.         if t=46 | t=33 | t=63        :rem  . ! ?
  100.             sp=2
  101.         endif
  102.         t=(xmax-(xloc+sectw))/(charw+spac)
  103.         sp=sp_t
  104.         center cent
  105.         move xloc,yloc
  106.         pen 1,clr
  107.         text $(word);
  108.         xloc=xloc+sectw+sp*(charw+spac)
  109.         if cent            :rem  centering forces newline
  110.             xloc=xmin
  111.             yloc=yloc+charh
  112.             if yloc > ymax
  113.                 gosub getevent
  114.             endif
  115.         endif
  116.         center 0
  117.         @(in)=c        :rem restore terminator
  118.         goto 11
  119.     endif
  120.  
  121. rem  section's too big, find subsection
  122.     t=0~((xmax-xloc)/(charw+spac)-1)        :rem  compute max chars
  123.  
  124. 14    if t=0            :rem  too near end of line
  125.         yloc=yloc+charh
  126.         if yloc > ymax
  127.             gosub getevent
  128.         endif
  129.         xloc=xmin
  130.         goto 13        :rem  retry this section on next line
  131.     endif
  132.     if @(word+t)#32        :rem  find word break
  133.         t=t-1
  134.         goto 14        :rem  keep moving
  135.     endif
  136.  
  137. rem  found space break
  138.     @(in)=c
  139.     in=word+t
  140.     c=@(in)
  141.     @(in)=0
  142.     goto 13        :rem  process shortened section
  143.  
  144. rem  getok
  145. 1000
  146.     center 0
  147.     pen 1,7
  148.     move 306,154
  149.     setfont 1
  150.     text "OK"
  151.     pen 1,4
  152.     move 295,145
  153.     draw 295,157
  154.     draw 332,157
  155.     draw 332,145
  156.     draw 295,145
  157. 1001
  158.     getmouse x,y
  159.     if x>295 & x<332 & y>145 & y<157
  160.         pen 1,0
  161.         rect 295,145,332,157
  162.         return
  163.     else
  164.         drawmode 2
  165.         pen 1,7
  166.         rect 295,145,332,157:pause 1
  167.         rect 295,145,332,157
  168.         goto 1001
  169.     endif
  170.     setfont font
  171.     return
  172.  
  173. rem  clears
  174. 1100
  175.     xloc=xmin:yloc=ymin
  176.     pen 1,0
  177.     rect 5,17,633,182
  178.     pen 1,clr
  179.     return
  180.  
  181. rem  docmd
  182. 1200
  183.     in=in+1
  184.     @(temp+1)=0
  185.     if @(in)=99        :rem  'c' for color
  186.         in=in+2
  187.         @(temp)=@(in-1)
  188.         clr=$(temp)
  189.         pen 1,clr
  190.         return
  191.     endif
  192.     if @(in)=102    :rem  'f' for font
  193.         in=in+2
  194.         @(temp)=@(in-1)
  195.         font=$(temp)
  196.         setfont font
  197.         if font=2
  198.             charw=10
  199.         else
  200.             charw=8
  201.         endif
  202.         return
  203.     endif
  204.     if @(in)=116    :rem   't' for centering
  205.         in=in+2
  206.         @(temp)=@(in-1)
  207.         cent=$(temp)
  208.         return
  209.     endif
  210.     if @(in)=114    :rem  'r' for forced return
  211.         in=in+2
  212.         @(temp)=@(in-1)
  213.         rets=$(temp)
  214.         xloc=xmin
  215.         yloc=yloc+charh*rets
  216.         if yloc > ymax
  217.             gosub getevent
  218.         endif
  219.         return
  220.     endif
  221.     if @(in)=115    :rem  's' for style
  222.         in=in+3
  223.         @(temp)=@(in-2)
  224.         styl=$(temp)
  225.         @(temp)=@(in-1)
  226.         spac=$(temp)
  227.         style styl,spac
  228.         return
  229.     endif
  230.     if @(in)=101    :rem  'e' for end of page
  231.         in=in+1
  232.         goto getevent        :rem  await page click
  233.     endif
  234.     if @(in)=esc    :rem  use || to output a |
  235.         in=in+1
  236.         move xloc,yloc
  237.         text "|";
  238.         sps=1
  239.         goto 1222    :rem  act like space from here
  240.     endif
  241.     if @(in)=45        :rem  '-' for backspace
  242.         in=in+1
  243.         xloc=(xloc-charw)~xmin
  244.         return
  245.     endif
  246.     if @(in)=43        :rem  '+' for required spaces
  247.         in=in+2
  248.         @(temp)=@(in-1)
  249.         sps=$(temp)
  250.         if sps=0:sps=10:endif
  251. 1222
  252.         xloc=xloc+charw*sps
  253.         if xloc>xmax
  254.             xloc=xmin
  255.             yloc=yloc+charh
  256.             if yloc > ymax
  257.                 gosub getevent
  258.             endif
  259.         endif
  260.         return
  261.     endif
  262.     return
  263.  
  264. rem  eof  -  handle backup from here as well
  265. 22    eof=1
  266.     gosub getevent
  267.     goto 10        :rem  next line
  268.  
  269. rem  getevent
  270. 1300
  271.     getmouse x,y
  272.  
  273. rem  quit box...
  274.     if x>9 & x<22 & y>4 & y<9
  275.         end
  276.     endif
  277.  
  278. rem  bkwd page
  279.     if x>243 & x<301 & y>184 & y<197
  280.         page=(page-2)~pstart
  281.         seek @(page)
  282.         page=page+1
  283.         eof=0
  284.         gosub clears
  285.         return
  286.     endif
  287.  
  288.     if eof
  289.         eof=0
  290.         return
  291.     endif
  292.  
  293. rem  fwd page
  294.     location v
  295.     @(page)=v    :rem  remember top of page location
  296.     page=page+1
  297.     gosub clears
  298.     return
  299.  
  300.